package com.ryan.day06;

/**
 * 实现冒泡排序
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] arr = {15,102,596,62,308,1,553,964,552,719,55,669,275,65,806,888,134,922,253,49,774,259,786,492,553,217,673,979,837,475,362,400,774,496,156,133,659,183,546,51,482,934,455,785,50,85,429,496,5};
        sort(arr);
        for (int i : arr) {
            System.out.print(i+" ");
        }
    }

    public static void sort(int[] arr){
        int temp = 0;//临时变量
        //比较的次数
        for (int i = 0; i < arr.length-1; i++) {
            //比较的个数
            for (int j = 0;j<arr.length-1-i;j++){
                //如果前面数字比后面大，则交换
                if (arr[j] > arr[j+1]){
                    temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }
}
